package com.luo.gmall.order.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Zoro
 * @date 2021年11月19
 */
@Configuration
public class ThreadPoolConfig {

    @Bean
    public ExecutorService executorService(
            @Value("${ThreadPool.corePoolSize}") Integer corePoolSize,
            @Value("${ThreadPool.maximumPoolSize}") Integer maximumPoolSize,
            @Value("${ThreadPool.keepAliveTime}") Integer keepAliveTime,
            @Value("${ThreadPool.blockQueueSize}") Integer blockQueueSize
    ) {
        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, new ArrayBlockingQueue<>(blockQueueSize));
    }
}
